<template>
  <div class="cu-common-layout">
    <div class="cu-common-layout-center">
      <el-row class="cu-common-search-box" :gutter="16">
        <el-form @submit.native.prevent>
          <el-col :span="4">
            <el-form-item label="校区品牌" prop="brand">
              <el-select v-model="query.brand" placeholder="">
                <el-option :key="item.id" :label="item.fullName" :value="item.enCode" v-for="item in brandOptions" />
              </el-select>
            </el-form-item>
          </el-col>
          <el-col :span="6">
            <el-form-item label="校区信息">
              <el-select v-model="query.campusId" placeholder="请选择校区" filterable clearable :loading="campusLoading" @focus="loadCampusOptions">
                <el-option v-for="item in campusOptions" :key="item.id" :label="item.fullName" :value="item.id" />
              </el-select>
            </el-form-item>
          </el-col>
          <el-col :span="6">
            <el-form-item label="帐号">
              <el-input v-model="query.account" clearable />
            </el-form-item>
          </el-col>
          <el-col :span="6">
            <el-form-item label="到期日期">
              <el-date-picker v-model="query.endDate" type="daterange" value-format="yyyy-MM-dd" format="yyyy-MM-dd" start-placeholder="开始日期" end-placeholder="结束日期"></el-date-picker>
            </el-form-item>
          </el-col>
          <el-col :span="6">
            <el-form-item>
              <el-button type="primary" icon="el-icon-search" @click="search()" native-type="submit">{{ $t('common.search') }}</el-button>
              <el-button icon="el-icon-refresh-right" @click="reset()">{{ $t('common.reset') }}</el-button>
            </el-form-item>
          </el-col>
        </el-form>
      </el-row>
      <div class="cu-common-layout-main cu-flex-main">
        <div class="cu-common-head">
          <div>
            <el-button type="primary" icon="el-icon-plus" @click="addOrUpdateHandle()" v-has="'btn_add'">新增</el-button>
            <el-button type="text" icon="el-icon-download" @click="exportData()" v-has="'btn_download'">导出</el-button>
            <el-button type="text" icon="el-icon-delete" @click="handleBatchRemoveDel()" v-has="'btn_batchRemove'">批量删除</el-button>
          </div>
          <div class="cu-common-head-right">
            <el-tooltip effect="dark" content="刷新" placement="top">
              <el-link icon="icon-ym icon-ym-Refresh cu-common-head-icon" :underline="false" @click="reset()" />
            </el-tooltip>
            <screenfull isContainer />
          </div>
        </div>
        <custom-table v-loading="listLoading" :data="list" has-c @selection-change="handleSelectionChange">
          <el-table-column label="校区" prop="campusId" align="left" v-if="custom.hasP('campusId')" width="200" show-overflow-tooltip></el-table-column>
          <!-- <el-table-column prop="standards" label="规格" align="left" v-if="custom.hasP('standards')" width="300" /> -->
          <el-table-column prop="goodsName" label="商品名称" align="left" width="200" show-overflow-tooltip></el-table-column>
          <el-table-column prop="typeName" label="商品规格" width="160" />
          <el-table-column prop="account" label="帐号" align="center" v-if="custom.hasP('account')" width="150">
            <template slot-scope="scope">
              <span v-if="scope.row.endDate <= +new Date()" style="color:red">{{ scope.row.account }}</span>
              <span v-else>{{ scope.row.account }}</span>
            </template>
          </el-table-column>
          <el-table-column prop="openDate" label="开通日期" align="center" v-if="custom.hasP('openDate')" :formatter="custom.tableDateFormat" width="100" />
          <el-table-column prop="startDate" label="开始日期" align="center" v-if="custom.hasP('startDate')" :formatter="custom.tableDateFormat" width="100" />
          <el-table-column prop="endDate" label="截止日期" align="center" v-if="custom.hasP('endDate')" :formatter="custom.tableDateFormat" width="100" />
          <el-table-column prop="matheVersion" label="数学版本" align="center" v-if="custom.hasP('matheVersion')" width="80">
            <template slot-scope="scope">
              {{ scope.row.matheVersion | dynamicText(matheVersionOptions) }}
            </template>
          </el-table-column>
          <el-table-column prop="price" label="价格" align="right" v-if="custom.hasP('price')" width="60" />
          <el-table-column prop="status" label="订单状态" align="center" v-if="custom.hasP('status')" width="70">
            <template slot-scope="scope">
              <el-tag v-if="scope.row.status == 0" key="正常" type="success" effect="dark">
                正常
              </el-tag>
              <el-tag v-else-if="scope.row.status == 2" key="退款" type="danger" effect="dark">
                退款
              </el-tag>
              <el-tag v-else-if="scope.row.status == 4" key="作废" type="info" effect="dark">
                作废
              </el-tag>
            </template>
          </el-table-column>
          <el-table-column prop="source" label="来源" align="center" v-if="custom.hasP('source')" width="60">
            <template slot-scope="scope">
              {{ scope.row.source | dynamicText(sourceOptions) }}
            </template>
          </el-table-column>
          <el-table-column prop="payNo" label="支付单号" align="center" v-if="custom.hasP('payNo')" width="300"></el-table-column>
          <el-table-column prop="description" label="备注" align="left" v-if="custom.hasP('description')" width="300" show-overflow-tooltip />
          <el-table-column prop="createTime" label="创建时间" align="center" v-if="custom.hasP('createTime')" :formatter="custom.tableDateTimeFormat" width="120" />
          <el-table-column prop="createUserName" label="创建用户" align="left" v-if="custom.hasP('createUserName')" show-overflow-tooltip />
          <el-table-column prop="updateTime" label="修改时间" align="center" v-if="custom.hasP('updateTime')" :formatter="custom.tableDateTimeFormat" width="120" />
          <el-table-column prop="updateUserName" label="修改用户" align="left" v-if="custom.hasP('updateUserName')" />
          <el-table-column label="操作" fixed="right" width="180" align="center">
            <template slot-scope="scope">
              <el-button type="text" size="mini" @click="recordHandle(scope.row.id)">历史</el-button>
              <el-button type="text" size="mini" v-has="'btn_clear'" @click="handleRemove(scope.row.id)" v-if="scope.row.account">清空账号</el-button>
              <el-button type="text" size="mini" @click="addOrUpdateHandle(scope.row.id)" v-has="'btn_edit'" v-if="scope.row.status == 0 && scope.row.account == null">编辑</el-button>
              <el-button type="text" size="mini" @click="handleDel(scope.row.id)" class="cu-table-delBtn" v-has="'btn_remove'">删除</el-button>
            </template>
          </el-table-column>
        </custom-table>
        <pagination :total="total" :page.sync="listQuery.currentPage" :limit.sync="listQuery.pageSize" @pagination="initData" />
      </div>
    </div>
    <custom-form v-if="formVisible" ref="CustomForm" @refresh="search" />
    <ExportBox v-if="exportBoxVisible" ref="ExportBox" @download="download" />
    <Records v-if="recordsVisible" ref="RecordsForm" />
  </div>
</template>
<script>
export { default } from './index.js'
</script>
<style lang="scss" scoped>
@import url(index.scss);
</style>
